<?php
//URL: http://localhost/ChampChooser/core/services/player/searchPlayerListService.php?filterString=
require_once ("../../config/config.php");
require_once ("../../config/constants.php");
require_once ("../../db/queries.php");
require_once ("../../common/common.php");

$filterString= $_REQUEST["filterString"];

function queryPlayers($filterString) {
	$searchStrings = split(' ',$filterString);	
	$strQuery ="select id,fname,lname,playerType,country,cost,points from player where ";
	$max_count = sizeof($searchStrings);
	for ( $index = 0 ; $index < $max_count; $index++ ) {
		$criteriaList = array("fname","lname","country","playerType");
		for ( $index2 = 0, $max_count2 = sizeof( $criteriaList ); $index2 < $max_count2; $index2++ ) {
			if($index2>0){
				$strQuery = $strQuery." or ".$criteriaList[$index2]." like '%".$searchStrings[$index]."%'";
			}
			else{
				$strQuery = $strQuery."( ".$criteriaList[$index2]." like '%".$searchStrings[$index]."%'";
			}
		}
		$strQuery = $strQuery.")";
		if($index < sizeof( $searchStrings)-1){
			$strQuery = $strQuery." AND ";
		}
	}
	
	return generateResultSet($strQuery);
}

makeQueryXML(queryPlayers($filterString));
?>